package org.benjamin.lending.domain.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.CreationTimestamp;

@Entity
@Table(name = "tab_borrow_info")
public class BorrowInfo implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	//借款对接编号
	@Column(name = "no",unique = true)
	private String no;
	
	//借款人
	@ManyToOne
	@JoinColumn(name = "borrower_id")
	private MemberInfo borrower;

	//借款标名
	@Column(name = "name",nullable = false)
	private String name;
	
	@ManyToOne
	@JoinColumn(name = "product_id")
	private Product product;

	//投资年化收益率
	@Column(name = "invest_rate",scale = 2,nullable = false)
	private BigDecimal investRate;

	//需要投资金额
	@Column(name = "total_money",nullable = false)
	private BigDecimal totalMoney;
	
	/**
	 * 借款期限
	 */
	@Column(name = "period",nullable = false)
	private Integer period;

	/**
	 * 状态
	 */
	@Enumerated(EnumType.STRING)
	@Column(name = "status")
	private Status status;
	
	//还款方式
	@Enumerated(EnumType.STRING)
	@Column(name = "repayment_method")
	private RepaymentMethod repaymentMethod;
	
	//计息方式
	@Column(name = "breath_day")
	private Integer breathDay;
	
	//投资金额
	@Column(name = "invest_money")
	private BigDecimal investMoney = BigDecimal.ZERO;
	
	//管理费
	@Column(name = "managent_fee",scale = 2)
	private BigDecimal managementFee = BigDecimal.ZERO;

	//创建时间
	@Column(name = "create_time")
	@CreationTimestamp
	private Timestamp createTime;

	//审计发标时间
	@Column(name = "trial_time", insertable = false)
	private Timestamp trialTime;

	//创建用户名
	@Column(name = "create_username")
	private String createUsername;

	//审计用户名
	@Column(name = "trial_username")
	private String trialUsername;

	//复审放款用户名
	@Column(name = "recheck_username")
	private String recheckUsername;
	
	@Lob
	@Column(name = "introduce")
	private String introduce;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public MemberInfo getBorrower() {
		return borrower;
	}

	public void setBorrower(MemberInfo borrower) {
		this.borrower = borrower;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public BigDecimal getInvestRate() {
		return investRate;
	}

	public void setInvestRate(BigDecimal investRate) {
		this.investRate = investRate;
	}

	public BigDecimal getInvestMoney() {
		return investMoney;
	}

	public void setInvestMoney(BigDecimal investMoney) {
		this.investMoney = investMoney;
	}

	public BigDecimal getTotalMoney() {
		return totalMoney;
	}

	public void setTotalMoney(BigDecimal totalMoney) {
		this.totalMoney = totalMoney;
	}

	public Integer getPeriod() {
		return period;
	}

	public void setPeriod(Integer period) {
		this.period = period;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}
	
	

	public RepaymentMethod getRepaymentMethod() {
		return repaymentMethod;
	}

	public void setRepaymentMethod(RepaymentMethod repaymentMethod) {
		this.repaymentMethod = repaymentMethod;
	}

	public Timestamp getCreateTime() {
		return createTime;
	}
	
	

	public Integer getBreathDay() {
		return breathDay;
	}

	public void setBreathDay(Integer breathDay) {
		this.breathDay = breathDay;
	}

	public BigDecimal getManagementFee() {
		return managementFee;
	}

	public void setManagementFee(BigDecimal managementFee) {
		this.managementFee = managementFee;
	}

	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}

	public Timestamp getTrialTime() {
		return trialTime;
	}

	public void setTrialTime(Timestamp trialTime) {
		this.trialTime = trialTime;
	}

	public String getCreateUsername() {
		return createUsername;
	}

	public void setCreateUsername(String createUsername) {
		this.createUsername = createUsername;
	}

	public String getTrialUsername() {
		return trialUsername;
	}

	public void setTrialUsername(String trialUsername) {
		this.trialUsername = trialUsername;
	}

	public String getRecheckUsername() {
		return recheckUsername;
	}

	public void setRecheckUsername(String recheckUsername) {
		this.recheckUsername = recheckUsername;
	}
	
	public String getIntroduce() {
		return introduce;
	}

	public void setIntroduce(String introduce) {
		this.introduce = introduce;
	}

	public enum RepaymentMethod implements Serializable{
		EQUAL_PRINCIPAL,EQUAL_PRINCIPAL_AND_INTEREST,REPAYMENT_DUE,AFTER_THE_FIRST_INTEREST
	}

	public enum Status  implements Serializable {
		TRIAL, RELEASE,FINISH,REPEAL,REPAY
	}

}
